import { useAuthStore } from "@/store";
import type { PropsWithChildren, ReactNode } from "react";

type AuthorizeProps = PropsWithChildren<{
	acl: string;
	/** 未授权时的渲染内容 */
	fallback?: ReactNode;
}>;

export default function Authorize({
	children,
	acl,
	fallback,
}: AuthorizeProps): ReactNode {
	const { isAuthorized } = useAuthStore();
	return isAuthorized(acl) ? children : fallback;
}
